<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <% include("../inc/list_css.html"){}%>
    <style>
        .btn-primary {
            background-color: #15baff !important;
        }
    </style>
</head>

<body>
<div class="ibox ">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span>财务管理 </span>
            <span class="line">/</span>
            佣金明细
        </div>
    </div>
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <input type="hidden" name="dataLevel" id="dataLevel" value="1">
            <input type="hidden" name="yesterday" id="yesterday" value="${yesterday}"/>
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-warning alert-dismissable">
                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                        当日营业额：<label class="totalAmount"></label> &nbsp;分红比例：<label class="rewardPercent"></label>
                        &nbsp;分红人数：<label class="rewardNum"></label> &nbsp;分红金额：<label class="rewardCash"></label>
                    </div>
                    <div class="btn-group margin-top-20">
                        <button class="reward statistic_btn hive-btn-primary" type="button" data="1" style="border-radius: 4px 0px 0px 4px;">一级分红</button>
                        <button class="reward statistic_btn" type="button" data="2" style="border-radius: 0px 0px 0px 0px;border-right: 0px;margin-left: -5px">二级分红</button>
                        <button class="reward statistic_btn" type="button" data="3" style="border-radius: 0px 0px 0px 0px;border-right: 0px;margin-left: -5px">三级分红</button>
                        <button class="reward statistic_btn" type="button" data="4" style="border-radius: 0px 0px 0px 0px;border-right: 0px;margin-left: -5px">四级分红</button>
                        <button class="reward statistic_btn" type="button" data="5" style="border-radius: 0px 0px 0px 0px;border-right: 0px;margin-left: -6px">五级分红</button>
                        <button class="reward statistic_btn" type="button" data="6" style="border-radius: 0px 4px 4px 0px;border-right: 0px;margin-left: -5px">六级分红</button>
                    </div>

                    <div id="toolbar" style="margin-top: 10px">
                        日期：<input class="laydate-icon" id="start" style="width:200px; margin-right:10px;"
                                  value="${yesterday}"/>
                        <button type="button" class="hive-btn hive-btn-primary" onclick="look()">查询</button>
                        <button type="button" class="hive-btn hive-btn-primary" onclick="exportprofit()">导出</button>
                        <button id="ok" type="button" class="hive-btn hive-btn-primary">生成分红金额</button>
                    </div>
                    <table id="cpTableEvents" data-toggle="table" data-mobile-responsive="true"
                           class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
                        <thead class="table-header">
                        <tr>
                            <th data-field="number" data-formatter="numberFormatter">序号</th>
                            <th data-field="code">会员ID</th>
                            <th data-field="username">会员昵称</th>
                            <th data-field="phone">联系方式</th>
                            <th data-field="rewardnum">值荐会员</th>
                            <th data-field="addMoney">分红金额</th>
                            <th data-field="status" data-formatter="boolFormatter">分红状态</th>
                            <th data-field="profitDate">日期</th>
                            <th data-field="distribution" data-formatter="opFormatter"><a href="javascript:void(0)"
                                                                                          onclick="distribution();"
                                                                                          style="color: red">[一键分配]</a>
                            </th>
                        </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>


<% include("../inc/list_js.html"){}%>
<script src="/res/plugins/laydate/laydate.js"></script>

<script>
    function exportprofit() {
        var profitDate = $("#start").val();
        var dataLevel = $("#dataLevel").val();
        location.href = 'exportPyjt?profitDate=' + profitDate + '&dataLevel=' + dataLevel + '';
    }
    function look() {
        var profitDate = $("#start").val();//生成分红日期
        var dataLevel = $("#dataLevel").val();
        if (!profitDate) {
            layer.msg("请选择日期!");
            return;
        }
        $('#cpTableEvents').bootstrapTable("refresh", {query: {type: dataLevel, profitDate: profitDate}});
    }
    function numberFormatter(value, row, index) {
        return index + 1;
    }
    function opFormatter(value, row, index) {
        var html = '';
        if (row.status) {
            html += '<a href="javascript:void(0)" );>[已分配]</a>';
        } else {
            //html+='<a href="javascript:void(0)" onclick="distribution(\''+row.id+'\');" style="color: red">[点击分配]</a>';
            html += '<a href="javascript:void(0)" style="color: red">[未分配]</a>';
        }
        return html;
    }
    function boolFormatter(v) {
        if (v)
            return '已分红';
        else
            return '未分红';
    }

    //分配金额
    function distribution() {
        layer.confirm('您确定要一键分配吗?操作后将不可撤销,请谨慎操作!', {
            btn: ['是', '否'] //按钮
        }, function () {
            layer.msg("正在分配中...");
            $.ajax({
                method: "post",
                url: '${base}/shop/balancedetail/distributionPyjt',
                data: {
                    profitDate: $("#start").val(),
                    dataLevel: $("#dataLevel").val(),
                },
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg("操作成功...");
                        $('#cpTableEvents').bootstrapTable("refresh", {
                            query: {
                                type: $("#dataLevel").val(),
                                profitDate: $("#start").val()
                            }
                        });
                        //location.href='${base}/shop/dividend/list';
                    } else {
                        layer.msg(data.desc);
                    }
                }
            });
        });


    }

    (function () {
        $('.reward').on('click', function (e) {
            $('.reward').removeClass('hive-btn-primary');
            $(this).addClass('hive-btn-primary');


            /*   $('.reward').removeClass('btn-primary').addClass('btn-white');
             $(this).removeClass('btn-white').addClass('btn-primary');*/

            $('#cpTableEvents').bootstrapTable("refresh", {
                query: {
                    type: $(this).attr('data'),
                    profitDate: $("#start").val()
                }
            });
            $("#dataLevel").attr("value", $(this).attr('data'))
        });
        $('#cpTableEvents').bootstrapTable({
            url: "ajaxPyjtList",
            dataType: 'json',
            contentType: 'application/json',
            search: true,
            searchAlign: 'right',
            pagination: true,
            showRefresh: true,
            pageSize: 20,
            showToggle: false,//是否显示card/table切换按钮
            showColumns: true,//是否显示内容列下拉框
            pageList: [20, 50, 100],
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            paginationHAlign: 'right', //right, left
            paginationVAlign: 'bottom',
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },
            responseHandler: function (res) {
                $("#dsh").html(res.length);
                return res;
            },
            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            },
        });

e.stopPropagation();
    })();

    //生成分红金额
    $("#ok").click(function () {
        var createDate = $("#start").val();//生成分红日期
        var dataLevel = $("#dataLevel").val();
        if (!createDate) {
            layer.msg("请选择日期!");
            return;
        }
        layer.msg("正在努力地加载中,请稍后.....")
        $.ajax({
            url: "${base}/shop/balancedetail/createPyjt",
            type: 'POST',
            data: {
                "createDate": createDate,
                "dataLevel": dataLevel
            },
            success: function (data) {
                if (data.code == 1) {
                    layer.msg(data.desc);

                } else if (data.code == 0) {
                    layer.msg("操作成功!");
                    $('#cpTableEvents').bootstrapTable("refresh", {
                        query: {
                            type: $("#dataLevel").val(),
                            profitDate: $("#start").val()
                        }
                    });
                }
            }
        });
    });
</script>
<script>
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD hh:mm:ss',
        //min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        //istime: true,
        istoday: false,
    };
    laydate(start);

</script>
</body>

</html>